// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StorageCredentialsWrapper.cs" company="AzureContrib (Open source library http://azurecontrib.codeplex.com)">
//   Microsoft Public License (Ms-PL)
// </copyright>
// <summary>
//   Implementation for <see cref="IStorageCredentials" /> that wraps around <see cref="StorageCredentials" />
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System.Net;
using Microsoft.WindowsAzure;

namespace AzureContrib.WindowsAzure.StorageClient
{
	using System;

	/// <summary>
	/// Implementation for <see cref="IStorageCredentials"/> that wraps around <see cref="StorageCredentials"/>
	/// </summary>
	public class StorageCredentialsWrapper : IStorageCredentials
	{
		private readonly StorageCredentials storageCredentials;

		/// <summary>
		/// Initializes a new instance of the <see cref="StorageCredentialsWrapper"/> class. 
		/// </summary>
		/// <param name="storageCredentials">
		/// Credentials to wrap up.
		/// </param>
		public StorageCredentialsWrapper(StorageCredentials storageCredentials)
		{
			this.storageCredentials = storageCredentials;
		}

		/// <summary>
		/// Gets a value indicating whether <see cref="StorageCredentials.AccountName"/> is set.
		/// </summary>
		public string AccountName
		{
			get { return storageCredentials.AccountName; }
		}

		/// <summary>
		/// Gets a value indicating whether <see cref="StorageCredentials.NeedsTransformUri"/> is true.
		/// </summary>
		public bool NeedsTransformUri
		{
			get { return storageCredentials.NeedsTransformUri; }
		}

		/// <summary>
		/// Gets a value indicating whether the Storage Credentials can sign a request. <seealso cref="StorageCredentials.CanSignRequest"/>
		/// </summary>
		public bool CanSignRequest
		{
			get { return storageCredentials.CanSignRequest; }
		}

		/// <summary>
		/// Gets a value indicating whether <see cref="StorageCredentials.CanSignRequestLite"/> is true.
		/// </summary>
		public bool CanSignRequestLite
		{
			get { return storageCredentials.CanSignRequestLite; }
		}

		/// <summary>
		/// Gets a value indicating whether <see cref="StorageCredentials.CanComputeHmac"/> is true.
		/// </summary>
		public bool CanComputeHmac
		{
			get { return storageCredentials.CanComputeHmac; }
		}

		/// <summary>
		/// Gets a value indicating whether the wrapped credentials are present and they are of type <see cref="StorageCredentials"/>.
		/// </summary>
		public object WrappedCredentials
		{
			get { return storageCredentials; }
		}

		/// <summary>
		/// Transforms a resource URI into the required format. For a shared access signature, TransformUri transforms a resource URI by appending a shared access token. <seealso cref="StorageCredentials.TransformUri"/>
		/// </summary>
		/// <param name="resource">
		/// The resourceUri is a <see cref="Uri"/>.
		/// </param>
		/// <returns>The transformed uri.</returns>
		public string TransformResource(string resource)
		{
			return storageCredentials.TransformUri(resource);
		}

		/// <summary>
		/// Signs a request using the specified credentials under the Shared Key authentication scheme. This is not a valid operation for objects of type <see cref="StorageCredentialsSharedAccessSignature"/>. <see cref="StorageCredentials.SignRequest"/>
		/// </summary>
		/// <param name="request">
		/// The request.
		/// </param>
		public void SignRequest(HttpWebRequest request)
		{
			storageCredentials.SignRequest(request);
		}

		/// <summary>
		/// See <see cref="StorageCredentials.SignRequestLite"/>
		/// </summary>
		/// <param name="request">
		/// The request.
		/// </param>
		public void SignRequestLite(HttpWebRequest request)
		{
			storageCredentials.SignRequestLite(request);
		}

		/// <summary>
		/// See <see cref="StorageCredentials.ComputeHmac"/>
		/// </summary>
		/// <param name="value">
		/// The value.
		/// </param>
		/// <returns>
		/// The compute hmac.
		/// </returns>
		public string ComputeHmac(string value)
		{
			return storageCredentials.ComputeHmac(value);
		}
	}
}